const express = require("express");
const session = require("express-session");
var router = express.Router();
// 配置中间件
router.use(session({
    secret: "express session",
    resave: false,
    saveUninitialized: true,
    cookie: ('name', 'value', {
        maxAge: 5 * 60 * 1000,
        secure: false
    })
}));
router.use('/login', function(req, res) {
    // 设置 session
    req.session.userinfo = '管理员';
    res.send("登录成功!");
});
router.use('/', function(req, res) {
    // 获取 session
    if (req.session.userinfo) {
        res.send("你好, " + req.session.userinfo + ", 欢迎访问本站!");
    } else {
        res.send("未登录");
    }
});
module.exports = router;